package com.theory.base.config;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableKnife4j
public class Swagger2Config {


    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("管理员API")
                .select()
                .paths(Predicates.and(PathSelectors.regex("/.*/admin/.*")))  // 设置路径过滤器，通过正则表达式过滤路径
                .apis(RequestHandlerSelectors.basePackage("com.theory"))
                .build();
    }

    @Bean
    public Docket docket2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("客户端API")
                .select()
                .paths(Predicates.and(PathSelectors.regex("/.*/api/.*")))  // 设置路径过滤器，通过正则表达式过滤路径
                .apis(RequestHandlerSelectors.basePackage("com.theory"))
                .build();
    }


    private ApiInfo apiInfo() {
        Contact contact = new Contact("theory", "https://www.baidu.com", "89645874@qq.com");
        return new ApiInfoBuilder()
                .title("尚融宝平台管理系统API文档")
                .description("本文档描述了尚融宝后台管理系统各个模块接口的调用方式")
                .version("1.0")
                .termsOfServiceUrl("https://www.baidu.com")
                .contact(contact)
                .build();
    }
}
